package thread;

import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @Description: 作用描述
 * @Author: hmm
 * @CreateDate: 2019/8/7$ 10:42$
 * @UpdateUser: hmm
 * @UpdateDate: 2019/8/7$ 10:42$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class CallableDemo {
    public static void main(String[] args) {
        Callable<Object> callable = new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                //Random random = new Random();
                String next = new Scanner(System.in).next();
                return next;
            }
        };
        FutureTask<Object> objectFutureTask = new FutureTask<Object>(callable);
        new Thread(objectFutureTask).start();
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("我是线程2");
            }
        });
        thread2.start();
        try {
            Object o = objectFutureTask.get();
            System.out.println(o);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
